// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PointGlyphAttributes.h>
#include <DataNode.h>

// ****************************************************************************
// Method: PointGlyphAttributes::PointGlyphAttributes
//
// Purpose:
//   Init utility for the PointGlyphAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

void PointGlyphAttributes::Init()
{
    pointSize = 0.05;
    pointType = Point;
    pointSizeVarEnabled = false;
    pointSizePixels = 2;

    PointGlyphAttributes::SelectAll();
}

// ****************************************************************************
// Method: PointGlyphAttributes::PointGlyphAttributes
//
// Purpose:
//   Copy utility for the PointGlyphAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

void PointGlyphAttributes::Copy(const PointGlyphAttributes &obj)
{
    pointSize = obj.pointSize;
    pointType = obj.pointType;
    pointSizeVarEnabled = obj.pointSizeVarEnabled;
    pointSizeVar = obj.pointSizeVar;
    pointSizePixels = obj.pointSizePixels;

    PointGlyphAttributes::SelectAll();
}

// Type map format string
const char *PointGlyphAttributes::TypeMapFormatString = POINTGLYPHATTRIBUTES_TMFS;
const AttributeGroup::private_tmfs_t PointGlyphAttributes::TmfsStruct = {POINTGLYPHATTRIBUTES_TMFS};


// ****************************************************************************
// Method: PointGlyphAttributes::PointGlyphAttributes
//
// Purpose:
//   Default constructor for the PointGlyphAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

PointGlyphAttributes::PointGlyphAttributes() :
    AttributeSubject(PointGlyphAttributes::TypeMapFormatString),
    pointSizeVar("default")
{
    PointGlyphAttributes::Init();
}

// ****************************************************************************
// Method: PointGlyphAttributes::PointGlyphAttributes
//
// Purpose:
//   Constructor for the derived classes of PointGlyphAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

PointGlyphAttributes::PointGlyphAttributes(private_tmfs_t tmfs) :
    AttributeSubject(tmfs.tmfs),
    pointSizeVar("default")
{
    PointGlyphAttributes::Init();
}

// ****************************************************************************
// Method: PointGlyphAttributes::PointGlyphAttributes
//
// Purpose:
//   Copy constructor for the PointGlyphAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

PointGlyphAttributes::PointGlyphAttributes(const PointGlyphAttributes &obj) :
    AttributeSubject(PointGlyphAttributes::TypeMapFormatString)
{
    PointGlyphAttributes::Copy(obj);
}

// ****************************************************************************
// Method: PointGlyphAttributes::PointGlyphAttributes
//
// Purpose:
//   Copy constructor for derived classes of the PointGlyphAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

PointGlyphAttributes::PointGlyphAttributes(const PointGlyphAttributes &obj, private_tmfs_t tmfs) :
    AttributeSubject(tmfs.tmfs)
{
    PointGlyphAttributes::Copy(obj);
}

// ****************************************************************************
// Method: PointGlyphAttributes::~PointGlyphAttributes
//
// Purpose:
//   Destructor for the PointGlyphAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

PointGlyphAttributes::~PointGlyphAttributes()
{
    // nothing here
}

// ****************************************************************************
// Method: PointGlyphAttributes::operator =
//
// Purpose:
//   Assignment operator for the PointGlyphAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

PointGlyphAttributes&
PointGlyphAttributes::operator = (const PointGlyphAttributes &obj)
{
    if (this == &obj) return *this;

    PointGlyphAttributes::Copy(obj);

    return *this;
}

// ****************************************************************************
// Method: PointGlyphAttributes::operator ==
//
// Purpose:
//   Comparison operator == for the PointGlyphAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

bool
PointGlyphAttributes::operator == (const PointGlyphAttributes &obj) const
{
    // Create the return value
    return ((pointSize == obj.pointSize) &&
            (pointType == obj.pointType) &&
            (pointSizeVarEnabled == obj.pointSizeVarEnabled) &&
            (pointSizeVar == obj.pointSizeVar) &&
            (pointSizePixels == obj.pointSizePixels));
}

// ****************************************************************************
// Method: PointGlyphAttributes::operator !=
//
// Purpose:
//   Comparison operator != for the PointGlyphAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

bool
PointGlyphAttributes::operator != (const PointGlyphAttributes &obj) const
{
    return !(this->operator == (obj));
}

// ****************************************************************************
// Method: PointGlyphAttributes::TypeName
//
// Purpose:
//   Type name method for the PointGlyphAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

const std::string
PointGlyphAttributes::TypeName() const
{
    return "PointGlyphAttributes";
}

// ****************************************************************************
// Method: PointGlyphAttributes::CopyAttributes
//
// Purpose:
//   CopyAttributes method for the PointGlyphAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

bool
PointGlyphAttributes::CopyAttributes(const AttributeGroup *atts)
{
    if(TypeName() != atts->TypeName())
        return false;

    // Call assignment operator.
    const PointGlyphAttributes *tmp = (const PointGlyphAttributes *)atts;
    *this = *tmp;

    return true;
}

// ****************************************************************************
// Method: PointGlyphAttributes::CreateCompatible
//
// Purpose:
//   CreateCompatible method for the PointGlyphAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

AttributeSubject *
PointGlyphAttributes::CreateCompatible(const std::string &tname) const
{
    AttributeSubject *retval = 0;
    if(TypeName() == tname)
        retval = new PointGlyphAttributes(*this);
    // Other cases could go here too.

    return retval;
}

// ****************************************************************************
// Method: PointGlyphAttributes::NewInstance
//
// Purpose:
//   NewInstance method for the PointGlyphAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

AttributeSubject *
PointGlyphAttributes::NewInstance(bool copy) const
{
    AttributeSubject *retval = 0;
    if(copy)
        retval = new PointGlyphAttributes(*this);
    else
        retval = new PointGlyphAttributes;

    return retval;
}

// ****************************************************************************
// Method: PointGlyphAttributes::SelectAll
//
// Purpose:
//   Selects all attributes.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

void
PointGlyphAttributes::SelectAll()
{
    Select(ID_pointSize,           (void *)&pointSize);
    Select(ID_pointType,           (void *)&pointType);
    Select(ID_pointSizeVarEnabled, (void *)&pointSizeVarEnabled);
    Select(ID_pointSizeVar,        (void *)&pointSizeVar);
    Select(ID_pointSizePixels,     (void *)&pointSizePixels);
}

///////////////////////////////////////////////////////////////////////////////
// Persistence methods
///////////////////////////////////////////////////////////////////////////////

// ****************************************************************************
// Method: PointGlyphAttributes::CreateNode
//
// Purpose:
//   This method creates a DataNode representation of the object so it can be saved to a config file.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

bool
PointGlyphAttributes::CreateNode(DataNode *parentNode, bool completeSave, bool forceAdd)
{
    if(parentNode == 0)
        return false;

    PointGlyphAttributes defaultObject;
    bool addToParent = false;
    // Create a node for PointGlyphAttributes.
    DataNode *node = new DataNode("PointGlyphAttributes");

    if(completeSave || !FieldsEqual(ID_pointSize, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("pointSize", pointSize));
    }

    if(completeSave || !FieldsEqual(ID_pointType, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("pointType", pointType));
    }

    if(completeSave || !FieldsEqual(ID_pointSizeVarEnabled, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("pointSizeVarEnabled", pointSizeVarEnabled));
    }

    if(completeSave || !FieldsEqual(ID_pointSizeVar, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("pointSizeVar", pointSizeVar));
    }

    if(completeSave || !FieldsEqual(ID_pointSizePixels, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("pointSizePixels", pointSizePixels));
    }


    // Add the node to the parent node.
    if(addToParent || forceAdd)
        parentNode->AddNode(node);
    else
        delete node;

    return (addToParent || forceAdd);
}

// ****************************************************************************
// Method: PointGlyphAttributes::SetFromNode
//
// Purpose:
//   This method sets attributes in this object from values in a DataNode representation of the object.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

void
PointGlyphAttributes::SetFromNode(DataNode *parentNode)
{
    if(parentNode == 0)
        return;

    DataNode *searchNode = parentNode->GetNode("PointGlyphAttributes");
    if(searchNode == 0)
        return;

    DataNode *node;
    if((node = searchNode->GetNode("pointSize")) != 0)
        SetPointSize(node->AsDouble());
    if((node = searchNode->GetNode("pointType")) != 0)
    {
        // Allow enums to be int or string in the config file
        if(node->GetNodeType() == INT_NODE)
        {
            int ival = node->AsInt();
            if(ival >= 0 && ival < 8)
                SetPointType(GlyphType(ival));
        }
        else if(node->GetNodeType() == STRING_NODE)
        {
            GlyphType value;
            if(GlyphType_FromString(node->AsString(), value))
                SetPointType(value);
        }
    }
    if((node = searchNode->GetNode("pointSizeVarEnabled")) != 0)
        SetPointSizeVarEnabled(node->AsBool());
    if((node = searchNode->GetNode("pointSizeVar")) != 0)
        SetPointSizeVar(node->AsString());
    if((node = searchNode->GetNode("pointSizePixels")) != 0)
        SetPointSizePixels(node->AsInt());
}

///////////////////////////////////////////////////////////////////////////////
// Set property methods
///////////////////////////////////////////////////////////////////////////////

void
PointGlyphAttributes::SetPointSize(double pointSize_)
{
    pointSize = pointSize_;
    Select(ID_pointSize, (void *)&pointSize);
}

void
PointGlyphAttributes::SetPointType(GlyphType pointType_)
{
    pointType = pointType_;
    Select(ID_pointType, (void *)&pointType);
}

void
PointGlyphAttributes::SetPointSizeVarEnabled(bool pointSizeVarEnabled_)
{
    pointSizeVarEnabled = pointSizeVarEnabled_;
    Select(ID_pointSizeVarEnabled, (void *)&pointSizeVarEnabled);
}

void
PointGlyphAttributes::SetPointSizeVar(const std::string &pointSizeVar_)
{
    pointSizeVar = pointSizeVar_;
    Select(ID_pointSizeVar, (void *)&pointSizeVar);
}

void
PointGlyphAttributes::SetPointSizePixels(int pointSizePixels_)
{
    pointSizePixels = pointSizePixels_;
    Select(ID_pointSizePixels, (void *)&pointSizePixels);
}

///////////////////////////////////////////////////////////////////////////////
// Get property methods
///////////////////////////////////////////////////////////////////////////////

double
PointGlyphAttributes::GetPointSize() const
{
    return pointSize;
}

GlyphType
PointGlyphAttributes::GetPointType() const
{
    return pointType;
}

bool
PointGlyphAttributes::GetPointSizeVarEnabled() const
{
    return pointSizeVarEnabled;
}

const std::string &
PointGlyphAttributes::GetPointSizeVar() const
{
    return pointSizeVar;
}

std::string &
PointGlyphAttributes::GetPointSizeVar()
{
    return pointSizeVar;
}

int
PointGlyphAttributes::GetPointSizePixels() const
{
    return pointSizePixels;
}

///////////////////////////////////////////////////////////////////////////////
// Select property methods
///////////////////////////////////////////////////////////////////////////////

void
PointGlyphAttributes::SelectPointSizeVar()
{
    Select(ID_pointSizeVar, (void *)&pointSizeVar);
}

///////////////////////////////////////////////////////////////////////////////
// Keyframing methods
///////////////////////////////////////////////////////////////////////////////

// ****************************************************************************
// Method: PointGlyphAttributes::GetFieldName
//
// Purpose:
//   This method returns the name of a field given its index.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

std::string
PointGlyphAttributes::GetFieldName(int index) const
{
    switch (index)
    {
    case ID_pointSize:           return "pointSize";
    case ID_pointType:           return "pointType";
    case ID_pointSizeVarEnabled: return "pointSizeVarEnabled";
    case ID_pointSizeVar:        return "pointSizeVar";
    case ID_pointSizePixels:     return "pointSizePixels";
    default:  return "invalid index";
    }
}

// ****************************************************************************
// Method: PointGlyphAttributes::GetFieldType
//
// Purpose:
//   This method returns the type of a field given its index.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

AttributeGroup::FieldType
PointGlyphAttributes::GetFieldType(int index) const
{
    switch (index)
    {
    case ID_pointSize:           return FieldType_double;
    case ID_pointType:           return FieldType_glyphtype;
    case ID_pointSizeVarEnabled: return FieldType_bool;
    case ID_pointSizeVar:        return FieldType_variablename;
    case ID_pointSizePixels:     return FieldType_int;
    default:  return FieldType_unknown;
    }
}

// ****************************************************************************
// Method: PointGlyphAttributes::GetFieldTypeName
//
// Purpose:
//   This method returns the name of a field type given its index.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

std::string
PointGlyphAttributes::GetFieldTypeName(int index) const
{
    switch (index)
    {
    case ID_pointSize:           return "double";
    case ID_pointType:           return "glyphtype";
    case ID_pointSizeVarEnabled: return "bool";
    case ID_pointSizeVar:        return "variablename";
    case ID_pointSizePixels:     return "int";
    default:  return "invalid index";
    }
}

// ****************************************************************************
// Method: PointGlyphAttributes::FieldsEqual
//
// Purpose:
//   This method compares two fields and return true if they are equal.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

bool
PointGlyphAttributes::FieldsEqual(int index_, const AttributeGroup *rhs) const
{
    const PointGlyphAttributes &obj = *((const PointGlyphAttributes*)rhs);
    bool retval = false;
    switch (index_)
    {
    case ID_pointSize:
        {  // new scope
        retval = (pointSize == obj.pointSize);
        }
        break;
    case ID_pointType:
        {  // new scope
        retval = (pointType == obj.pointType);
        }
        break;
    case ID_pointSizeVarEnabled:
        {  // new scope
        retval = (pointSizeVarEnabled == obj.pointSizeVarEnabled);
        }
        break;
    case ID_pointSizeVar:
        {  // new scope
        retval = (pointSizeVar == obj.pointSizeVar);
        }
        break;
    case ID_pointSizePixels:
        {  // new scope
        retval = (pointSizePixels == obj.pointSizePixels);
        }
        break;
    default: retval = false;
    }

    return retval;
}

///////////////////////////////////////////////////////////////////////////////
// User-defined methods.
///////////////////////////////////////////////////////////////////////////////

// ****************************************************************************
// Modifications:
//
// ****************************************************************************
bool
PointGlyphAttributes::ChangesRequireRecalculation(const PointGlyphAttributes &obj) const
{
   bool needSecondaryVar = (obj.pointType != Point &&
                            obj.pointType != Sphere &&
                            obj.pointSizeVarEnabled &&
                            obj.pointSizeVar != pointSizeVar &&
                            obj.pointSizeVar != "default" &&
                            obj.pointSizeVar != "" &&
                            obj.pointSizeVar != "\0");

    // Certain point type changes require a recalculation.
    bool currentPointTypeIsPoint =     pointType == Point;
    bool newPointTypeIsPoint     = obj.pointType == Point;

    bool changingPointType =  pointType != obj.pointType && currentPointTypeIsPoint != newPointTypeIsPoint;

    return needSecondaryVar || changingPointType;
}

